In [ ]:
! pip install conx -U
In [1]:
from conx import Network
In [2]:
net = Network(2, 2, 1)
In [3]:
inputs = [[0, 0],
          [0, 1],
          [1, 0],
          [1, 1]]

def xor(inputs):
    a = inputs[0]
    b = inputs[1]
    return [int((a or b) and not(a and b))]

net.set_inputs(inputs)
net.set_target_function(xor)
In [4]:
net.test()
--------------------------------------------------
Test:
Input: [0, 0]
Output: [ 0.74875197]

Input: [0, 1]
Output: [ 0.74896436]

Input: [1, 0]
Output: [ 0.74200833]

Input: [1, 1]
Output: [ 0.74127745]

--------------------------------------------------
Epoch: 0 TSS error: 1.23970035705 %correct: 0.0
In [5]:
%%time
net.train()
--------------------------------------------------
Training for max trails: 5000 ...
Epoch: 0 TSS error: 1.23970035705 %correct: 0.0
Epoch: 500 TSS error: 0.990417151637 %correct: 0.0
Epoch: 1000 TSS error: 0.92610197098 %correct: 0.0
Epoch: 1500 TSS error: 0.72078861406 %correct: 0.0
Epoch: 2000 TSS error: 0.19019734546 %correct: 0.0
Epoch: 2500 TSS error: 0.05709380045 %correct: 0.0
--------------------------------------------------
Epoch: 2844 TSS error: 0.036218270215 %correct: 1.0
CPU times: user 2.19 s, sys: 28 ms, total: 2.21 s
Wall time: 2.18 s
In [6]:
net.test()
--------------------------------------------------
Test:
Input: [1, 0]
Output: [ 0.90276211]

Input: [0, 0]
Output: [ 0.09716267]

Input: [1, 1]
Output: [ 0.08541021]

Input: [0, 1]
Output: [ 0.90000903]

--------------------------------------------------
Epoch: 2844 TSS error: 0.0361888890534 %correct: 1.0